<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
             <j-select-inFo
                :disabled="disableSubmit"
                :msg="dataId"
                v-decorator="['yongHuBiaoShi', validatorRules.yongHuBiaoShi]"
                :trigger-change="true"
                @addChange='nameId'
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="测量时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date
                :disabled="disableSubmit"
                placeholder="请选择测量时间"
                v-decorator="['ceLiangShiJian', validatorRules.ceLiangShiJian]"
                :trigger-change="true"
                style="width: 100%"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="身高" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input
                :disabled="disableSubmit"
                v-decorator="['shenGao', validatorRules.shenGao]"
                placeholder="请输入身高"
              ></a-input> </a-form-item
          ></a-col>
          <a-col :span="12">
            <a-form-item label="体重" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input
                :disabled="disableSubmit"
                v-decorator="['tiZhong', validatorRules.tiZhong]"
                placeholder="请输入体重"
              ></a-input>
            </a-form-item>
          </a-col> </a-row
        ><a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="BMI值" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input
                :disabled="disableSubmit"
                v-decorator="['bmiZhi', validatorRules.bmiZhi]"
                placeholder="请输入BMI值"
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="分析结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag
                :disabled="true"
                type="list"
                v-decorator="['fenXiJieGuo', validatorRules.fenXiJieGuo]"
                :trigger-change="true"
                dictCode="gkak_fxjg"
                placeholder="请选择分析结果"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-shebei
                :msg="dataSheBei"
                :disabled="disableSubmit"
                v-decorator="['sheBeiMingCheng', validatorRules.sheBeiMingCheng]"
                :trigger-change="true"
                @addChange='SheBeiName'
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="设备序列号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input
                :disabled="disableSubmit"
                v-decorator="['sheBeiXuLieHao', validatorRules.sheBeiXuLieHao]"
                placeholder="请输入设备序列号"
              ></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea
                :disabled="disableSubmit"
                v-decorator="['beiZhu', validatorRules.beiZhu]"
                rows="4"
                placeholder="请输入备注"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'
import JDate from '@/components/jeecg/JDate'
import JDictSelectTag from '@/components/dict/JDictSelectTag'

import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import JSelectInFo from '@/components/jeecgbiz/JSelectInFo'
import jSelectShebei from '@/components/jeecgbiz/jSelectShebei'

export default {
  name: 'GkakJkBmiCaiJiModal',
  components: {
    JDate,
    JSelectInFo,JDictSelectTag,
    JSearchSelectTag,
    jSelectShebei
  },
  data() {
    return {
      form: this.$form.createForm(this),
      title: '操作',
      width: 800,
      dataId: {},
      dataSheBei:{},
      addXingMing:"",

      disableSubmit: false,
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        yongHuBiaoShi: { rules: [{ required: true, message: '请输入姓名!' }] },
        ceLiangShiJian: { rules: [{ required: true, message: '请输入测量时间!' }] },
        shenGao: { rules: [{ required: true, message: '请输入身高!' }] },
        tiZhong: { rules: [{ required: true, message: '请输入体重!' }] },

        beiZhu: { rules: [] },
        bmiZhi: { rules: [] },
        fenXiJieGuo: { rules: [] },
        sheBeiMingCheng: { rules: [] },
        sheBeiXuLieHao: { rules: [] }
      },
      url: {
        add: '/gkakJkBmiCaiJi/add',
        edit: '/gkakJkBmiCaiJi/edit'
      }
    }
  },
  created() {},
  methods: {
     // 选择人员（健康信息）id后 查找改人员的设备 
    nameId(val){
      debugger
      this.$store.commit("personnelId",val.id)
    },
    SheBeiName(val){
      this.addXingMing=val.id
    },
    inFoId(record) {
        this.$store.commit("personnelId",record.yongHuBiaoShi)
        this.dataId = {
          id: record.yongHuBiaoShi,
          name: record.xingMing
        }
        this.dataSheBei={
          id: record.sheBeiId,
          name: record.sheBeiMingCheng
        }
     
    },
    add() {
      this.edit({})
    },
    edit(record) {
              this.inFoId(record)

      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(
            this.model,
            'xingMing',
            'yongHuBiaoShi',
            'ceLiangShiJian',
            'shenGao',
            'tiZhong',
            'beiZhu',
            'bmiZhi',
            'fenXiJieGuo',
            'sheBeiId',
            'sheBeiMingCheng',
            'sheBeiXuLieHao'
          )
        )
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          values.sheBeiId= this.addXingMing
          let formData = Object.assign(this.model, values)
          console.log('表单提交数据', formData)
          httpAction(httpurl, formData, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    popupCallback(row) {
      this.form.setFieldsValue(
        pick(
          row,
          'xingMing',
          'ceLiangShiJian',
          'yongHuBiaoShi',
          'shenGao',
          'tiZhong',
          'beiZhu',
          'bmiZhi',
          'fenXiJieGuo',
          'sheBeiId',
          'sheBeiMingCheng',
          'sheBeiXuLieHao'
        )
      )
    }
  }
}
</script>
